package javabase.collection.list.listsort;

import java.text.CollationKey;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * <pre>
 *   Title: ListSortDemo001.java
 *   Description: 
 *   Copyright: yundaex.com Copyright (c) 2013
 *   Company: 上海韵达货运有限公司
 * </pre>
 * 
 * @author liuzhaoqing
 * @version 1.0
 * @date 2014年11月5日
 */

public class CollationKeyDemo001 {
	
	public static void main(String[] args) {
		// 实例化
		Collator collator = Collator.getInstance();
		
		// 将该 String 转换为一系列可以和其他 CollationKey 按位进行比较的位
		CollationKey key1 = collator.getCollationKey("aowm"); 
		CollationKey key2 = collator.getCollationKey("zopq"); 
		CollationKey key3 = collator.getCollationKey("choz"); 
		CollationKey key4 = collator.getCollationKey("whom"); 
		CollationKey key5 = collator.getCollationKey("homa"); 

		List<CollationKey> list = new ArrayList<CollationKey>();
		list.add(key1);
		list.add(key2);
		list.add(key3);
		list.add(key4);
		list.add(key5);
//		Collections.sort(list, collator);
		// [thom, Thom, Thomas, tom, Tom]
		printCollection(list);
		
	} 
	static private void printCollection(Collection<?> collection) { 
		boolean first = true; 
		Iterator<?> iterator = collection.iterator(); 
		System.out.print("["); 
		while (iterator.hasNext()) { 
			if (first) { 
				first = false; 
			} else { 
				System.out.print(", "); 
			} 
			CollationKey key = (CollationKey)iterator.next(); 
			System.out.print(key.getSourceString()); 
		} 
		System.out.println("]"); 
	}

}
